import {Component, OnInit} from '@angular/core';
import {HttpClient} from '@angular/common/http';

@Component({
  selector: 'app-user-list',
  templateUrl: './user-list.component.html',
  styleUrls: ['./user-list.component.css']
})
export class UserListComponent implements OnInit {
  url = 'http://192.168.31.138:8080/lx/';
  userList = [];


  constructor(
    private http: HttpClient
  ) {
  }

  ngOnInit() {

    this.getUserList();
  }

  getUserList() {
    this.http.get(this.url + 'findAllByIfDelete').subscribe(v => {
      console.log(v);
      if (v['code'] === 0) {
        this.userList = v['data'];
      }
    })
  }

  delme(id) {
    let cf = confirm('是否删除?');
    if (cf) {
      this.http.post(this.url + 'deleteUser', id).subscribe(v => {
        if (v['code'] === 0) {
          alert('删除成功!');
          this.getUserList();
        } else {
          alert('删除失败!');
        }
      })
    }
  }

}
